package com.example.demo.Controller;

import com.example.demo.Service.UserService;
import com.example.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    public UserService userService;
    @RequestMapping("/login")
    public boolean login(User userInfo1, HttpSession session){
       if(userInfo1.getUsername()==null||userInfo1.getPassword()==null){
           return false;
       }

       User userInfo11 = new User();
     userInfo11 =  userService.selectByName(userInfo1);
     if(userInfo11==null){
         return false;
     }
   if(userInfo11.getUsername().equals(userInfo1.getUsername())&&userInfo11.getPassword().equals(userInfo1.getPassword())){
       session.setAttribute("user",userInfo11);
       return true;
   }
   return false;
    }
}
